# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an

from PyQt5.QtWidgets import *
import sys
from PyQt5.QtCore import *


class Men(QMainWindow):
    def __init__(self):
        super(Men, self).__init__()

        layout = QHBoxLayout()

        # 实例化主窗口的QMenuBar对象
        bar = self.menuBar()
        # 向菜单栏中添加新的QMenu对象，父菜单
        file = bar.addMenu("File")
        # 添加子窗口
        file.addAction("New")

        save = QAction("Save",self)
        # 字符串写法固定，不能出现空格("Ctrl+ S")
        save.setShortcut("Ctrl+S")
        file.addAction(save)

        # 添加可添加孙窗口的子菜单
        edit = file.addMenu("Edit")
        edit.addAction("copy")
        edit.addAction("paste")

        quit = QAction("Quit",self)
        file.addAction(quit)

        # 绑定全局信号槽
        file.triggered[QAction].connect(self.btn_)

        self.setLayout(layout)

    def btn_(self,q):
        print(q.text(),"is triggered")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    men = Men()
    men.show()
    sys.exit(app.exec_())